import time

from src.char.BaseChar import BaseChar


class Chisa(BaseChar):

    def do_perform(self):
        timeout = 2.5
        if self.has_intro:
            self.continues_normal_attack(0.8)
            timeout = 2.3
        if self.flying() and not self.liberation_available() and not self.resonance_available():
            self.wait_down()
        self.click_echo()
        start = time.time()
        while time.time() - start < timeout: 
            if time.time() - start < 0.5 and self.click_liberation():
                start = time.time()
                timeout = 10
                self.sleep(0.2)
            if time.time() - start < 0.5 and not self.is_forte_full() and self.click_resonance()[0]:
                start = time.time()
                if timeout != 10:
                    timeout = 1.7
            if self.is_forte_full() and self.perform_forte():
                return self.switch_next_char()  
            self.click()
            self.check_combat()
            self.task.next_frame()        
        self.switch_next_char()

    def perform_forte(self):
        if self.flying():
            self.wait_down()
        self.task.send_key(self.get_resonance_key(), down_time=1.2)
        if self.is_forte_full():
            return False
        self.heavy_attack(3.5)
        return True
